// pages/personal/week/week.js


const getweek = 'https://shop1.mollyfantasy.universal-space.cn/p14/app/member/getweekplan';

const svaeweek = 'https://shop1.mollyfantasy.universal-space.cn/p14/app/member/weekplan'

const token = wx.getStorageSync("utoken");

Page({


  /**
   * 页面的初始数据
   */
  data: {

      day: 1,
      min: 10,
      
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

      console.log(token),

      wx.request({
        url: getweek,
        header: {
         
          "utoken":token
        },
        dataType:'json',
        method: 'POST',
        
        success: (result)=>{

            if(result.data.data != null){

               this.setData({

                day: result.data.data.dayPerWeek,
                min: result.data.data.minutePerDay
               
              })

            

            }else{

              this.setData({

                day: 1,
                min: 10

              })

            }
           
        },
        fail: ()=>{},
        complete: ()=>{}
      });
  },

  dayChange:function(e){
    this.setData({
      day: e.detail.value
    })
  },

  minChange:function(e){
    this.setData({
      min: e.detail.value
    })

  },

  confirmOnClick:function(){

    var appInst =  getApp();
     
    

    appInst.globalData.day = this.data.day,
    appInst.globalData.min = this.data.min

       wx.request({
        url: svaeweek,
        data: {
          'day':this.data.day,
          'minute':this.data.min
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded',
          "utoken":token

        
        },
        method: 'POST',
        success: (result)=>{
          
        
          wx.switchTab({
            url: '/pages/personal/personal',
            success: (result)=>{

              

            },
            fail: ()=>{},
            complete: ()=>{}
          });

          wx.showToast({
            title: 'Save successfully',
            duration: 1000,
          });

         
        },
        fail: ()=>{},
        complete: ()=>{}
      });        


  }

})